/**
 * SoundEvent.java
 * @author Daniel Liu
 * Create: 2006-12-23 ����11:51:06
 */
package org.lex.ftp.util;

import java.net.URL;

import org.lex.ftp.FTP;
import org.lex.ftp.util.prefs.Keys;
import org.lex.sound.AudioPlayer;
import org.lex.utils.pool.DaemonExecutor;


public class Sound {
	private Sound() {
	}

	public static void connect() {
		playConfigFile(Keys.SOUND_CONNECT);
	}

	public static void disconnect() {
		playConfigFile(Keys.SOUND_DISCONNECT);
	}

	public static void complete() {
		playConfigFile(Keys.SOUND_COMPLETE);
	}

	public static void error() {
		playConfigFile(Keys.SOUND_ERROR);
	}

	public static void play(URL url, boolean checkSoundEnabled) {
		if (true == checkSoundEnabled && false == isSoundEnabled())
			return;
		DaemonExecutor.execute(AudioPlayer.newPlayer(url));
	}

	private static boolean isSoundEnabled() {
		return FTP.getContext().getResourceMap().getBoolean(Keys.SOUND_ENABLED);
	}

	private static void playConfigFile(String key) {
		String path = FTP.getContext().getResourceMap().getString(key);
		play(Sound.class.getResource(path), true);
	}
}
